//
//  GongGaoViewController.m
//  werfgh
//
//  Created by 李晓勇 on 14-9-20.
//  Copyright (c) 2014年 dingshenwangluokeji. All rights reserved.
//

#import "GongGaoViewController.h"
#import "Header.h"
@interface GongGaoViewController ()<UIWebViewDelegate>
{
UIActivityIndicatorView *activityIndicator;
}

@end

@implementation GongGaoViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    self.view.backgroundColor=[UIColor whiteColor];
    [super viewDidLoad];
    if (IOS7) {
        self.edgesForExtendedLayout=NO;
    }
    UIWebView*webView=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, DeviceHeight)];
        [self addBack];
    webView.delegate=self;
    //webView.scalesPageToFit=YES;
    
    [self.view addSubview:webView];
    NSString*str=[self.urlStr stringByReplacingOccurrencesOfString:@"'\'" withString:@""];
    NSLog(@"qqq%@",str);
    
    NSURL *url=[NSURL URLWithString:str];
    NSURLRequest *request=[NSURLRequest requestWithURL:url];
    [webView loadRequest:request];
    // Do any additional setup after loading the view.
}
-(void)addBack
{
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(11, 11, 22, 22);
    
    [backBtn setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(doBack:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    self.navigationItem.leftBarButtonItem = backItem;    // Do any additional setup after loading the view.
//    UIView*view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
//    view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"navgationbar.png"]];
//    [view addSubview:backBtn];
//    [self.view addSubview:view];
}

-(void)doBack:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
//-(NSString*)switchString:(NSString*)str
//{
//    for (int i; i<strlen(str); i++) {
//        if (i=='\') {
//            <#statements#>
//        }
//    }
//}
- (void) webViewDidStartLoad:(UIWebView *)webView
{
    //创建UIActivityIndicatorView背底半透明View
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    [view setTag:108];
    [view setBackgroundColor:[UIColor blackColor]];
    [view setAlpha:0.5];
    [self.view addSubview:view];
    
    activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)];
    [activityIndicator setCenter:view.center];
    [activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
    [view addSubview:activityIndicator];
    
    [activityIndicator startAnimating];
}
- (void) webViewDidFinishLoad:(UIWebView *)webView
{
    [activityIndicator stopAnimating];
    UIView *view = (UIView*)[self.view viewWithTag:108];
    [view removeFromSuperview];
    NSLog(@"webViewDidFinishLoad");
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
 {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
